package com.ruoyi.temu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.temu.domain.TemuSubPurchaseOrder;
import com.ruoyi.temu.service.ITemuSubPurchaseOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 备货单Controller
 * 
 * @author ruoyi
 * @date 2023-09-25
 */
@RestController
@RequestMapping("/temu/sub_purchase_order")
public class TemuSubPurchaseOrderController extends BaseController
{
    @Autowired
    private ITemuSubPurchaseOrderService temuSubPurchaseOrderService;

    /**
     * 查询备货单列表
     */
    @PreAuthorize("@ss.hasPermi('temu:sub_purchase_order:list')")
    @GetMapping("/list")
    public TableDataInfo list(TemuSubPurchaseOrder temuSubPurchaseOrder)
    {
        startPage();
        List<TemuSubPurchaseOrder> list = temuSubPurchaseOrderService.selectTemuSubPurchaseOrderList(temuSubPurchaseOrder);
        return getDataTable(list);
    }

    /**
     * 导出备货单列表
     */
    @PreAuthorize("@ss.hasPermi('temu:sub_purchase_order:export')")
    @Log(title = "备货单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TemuSubPurchaseOrder temuSubPurchaseOrder)
    {
        List<TemuSubPurchaseOrder> list = temuSubPurchaseOrderService.selectTemuSubPurchaseOrderList(temuSubPurchaseOrder);
        ExcelUtil<TemuSubPurchaseOrder> util = new ExcelUtil<TemuSubPurchaseOrder>(TemuSubPurchaseOrder.class);
        util.exportExcel(response, list, "备货单数据");
    }

    /**
     * 获取备货单详细信息
     */
    @PreAuthorize("@ss.hasPermi('temu:sub_purchase_order:query')")
    @GetMapping(value = "/{subPurchaseOrderSn}")
    public AjaxResult getInfo(@PathVariable("subPurchaseOrderSn") String subPurchaseOrderSn)
    {
        return success(temuSubPurchaseOrderService.selectTemuSubPurchaseOrderBySubPurchaseOrderSn(subPurchaseOrderSn));
    }

    /**
     * 新增备货单
     */
    @PreAuthorize("@ss.hasPermi('temu:sub_purchase_order:add')")
    @Log(title = "备货单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TemuSubPurchaseOrder temuSubPurchaseOrder)
    {
        return toAjax(temuSubPurchaseOrderService.insertTemuSubPurchaseOrder(temuSubPurchaseOrder));
    }

    /**
     * 修改备货单
     */
    @PreAuthorize("@ss.hasPermi('temu:sub_purchase_order:edit')")
    @Log(title = "备货单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TemuSubPurchaseOrder temuSubPurchaseOrder)
    {
        return toAjax(temuSubPurchaseOrderService.updateTemuSubPurchaseOrder(temuSubPurchaseOrder));
    }

    /**
     * 删除备货单
     */
    @PreAuthorize("@ss.hasPermi('temu:sub_purchase_order:remove')")
    @Log(title = "备货单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{subPurchaseOrderSns}")
    public AjaxResult remove(@PathVariable String[] subPurchaseOrderSns)
    {
        return toAjax(temuSubPurchaseOrderService.deleteTemuSubPurchaseOrderBySubPurchaseOrderSns(subPurchaseOrderSns));
    }
}
